<!--
 * @FileDescription 横滚角
 * @Author 杨宇翔
 * @Date 20220706 11:00:01
 * @LastEditors 杨宇翔
 * @LastEditTime 20220706 11:00:01
-->
<template>
    <div class="roll-angle">
        <div ref="container" class="chart">
        </div>
        <div class="information">
            <span>横滚角</span>
            <span>{{ roll }}</span>
        </div>
    </div>
</template>

<script setup lang="ts">
import { EChartsType, init } from 'echarts';
import { computed, onMounted, onUnmounted, ref, Ref, watch } from 'vue';
import { ProtocolComponent } from './InertialNavigationComponent';

const roll = computed(() => ProtocolComponent.Default.Frame.Roll)

watch(roll, value => chart?.setOption({
    series: [
        {
            data: [value],
        }
    ]
}));

const container: Ref<HTMLDivElement | null> = ref(null);
let chart: EChartsType | null = null;

onMounted(async () => {
    chart = init(container.value!, 'dark');
    const option = {
        backgroundColor: 'transparent',
        tooltip: {
            show: false,
        },
        series: [
            {
                name: '横滚角',
                type: 'gauge',
                min: -150,
                max: 150,
                progress: {
                    show: false,
                },
                detail: {
                    valueAnimation: false,
                    show: false,
                },
                title: {
                    show: false,
                },
                axisLine: {
                    show: false,
                },
                axisLabel: {
                    distance: -20,
                },
                splitLine: {
                    distance: 12,
                    length: '10%',
                },
                axisTick: {
                    distance: 16,
                    length: '5%',
                },
                anchor: {
                    show: true,
                    showAbove: true,
                    size: 16,
                    itemStyle: {
                        color: "rgba(177, 177, 212, 1)"
                    }
                },
                pointer: {
                    show: true,
                    keepAspect: true,
                    length: '50%',
                    width: 3,
                    itemStyle: {
                        color: "rgba(200, 42, 42, 1)"
                    }
                },
                data: [
                    {
                        value: roll.value,
                        name: '°'
                    }
                ]
            }
        ]
    };
    chart.setOption(option);
});

onUnmounted(() => {
    chart?.dispose();
});
</script>

<style scoped>
.roll-angle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7rem;
}

.chart {
    width: 20rem;
    height: 20rem;
}

.information {
    display: flex;
    justify-content: center;
    align-items: center;
}

span {
    display: inline-block;
    width: 12rem;

    color: #81859C;
    font-size: 1.8rem;

    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

span:last-of-type {
    display: inline-block;

    width: 15rem;
    height: 3.6rem;
    color: #B1B1D4;
    font-size: 1.8rem;
    line-height: 3.6rem;
    text-align: center;

    border: solid 0.1rem #36384B;

    opacity: 0.5;
}

span:last-of-type:hover {
    border: solid 0.1rem;
    border-image: linear-gradient(90deg, rgba(128, 125, 225, 1), rgba(33, 140, 222, 1)) 1 1;

    opacity: 1;
}
</style>